import sys
import math
from bisect import bisect_left


def main():
    input = sys.stdin.read().split()
    idx = 0
    n = int(input[idx])
    idx += 1
    a = list(map(int, input[idx:idx + n]))
    idx += n

    block_size = int(n**0.5) + 1  # 块的大小
    num_blocks = n//block_size+1  # 块的数量
    blocks = []  # 维护每块的有序数组
    for i in range(num_blocks):
        start = i * block_size
        end = min((i + 1) * block_size, n)
        block = sorted(a[start:end])
        blocks.append(block)

    m = int(input[idx])
    idx += 1
    output = []

    for _ in range(m):
        op = input[idx]
        idx+=1
        if op == '1':
            # # 更新某点的值
            x ,y= int(input[idx]) - 1,int(input[idx+1])
            idx += 2
            a[x] = y
            block_idx = x // block_size
            start = block_idx * block_size
            end = min((block_idx + 1) * block_size, n)
            # 更新当前块的值
            blocks[block_idx] = sorted(a[start:end])
        else:
            # 查询第几小的值
            l,r,p = int(input[idx]) - 1,int(input[idx+1]) - 1,int(input[idx+2]) - 1
            idx += 3
            v = a[p]
            res = 0

            l_block = l // block_size
            r_block = r // block_size
            # 遍历块id
            for i in range(l_block, r_block + 1):
                block_start = i * block_size
                block_end = min((i + 1) * block_size, n)
                # Determine the overlap between [l, r] and [block_start, block_end-1]
                current_l = max(l, block_start)
                current_r = min(r, block_end - 1)
                if current_l > current_r:
                    continue
                # 中间块
                if current_l == block_start and current_r == block_end - 1:
                    # 去当前块的数组
                    block = blocks[i]
                    # 二分查找
                    res+=bisect_left(block, v)
                # 左右两块
                else:
                    for pos in range(current_l, current_r + 1):
                        if a[pos] < v:
                            res += 1
            output.append(str(res + 1))

    print(' '.join(output))


if __name__ == '__main__':
    main()